package com.Lyy.Controller;

import com.Lyy.Entity.Student;
import com.Lyy.Service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/Student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public List<Student> SelectStudentAll() {
        return studentService.SelectStudentAll();
    }
    @GetMapping (params = "studentName")
    public List<Student> SelectStudentName(String studentName) {
        return studentService.SelectStudentName(studentName);
    }
    @GetMapping("{studentId}")
    public Student SelectStudentById(@PathVariable String studentId) {
        return studentService.SelectStudentById(Integer.parseInt(studentId));
    }
    @PutMapping
    public int UpdateStudent(@RequestBody Student student) {
        return studentService.UpdateStudent(student);
    }
    @DeleteMapping("{studentId}")
    public int DeleteStudentById(@PathVariable String studentId) {
        return studentService.DeleteStudentById(Integer.parseInt(studentId));
    }
    @PostMapping
    public int InsertStudent(@RequestBody Student student) {
        return studentService.InsertStudent(student);
    }
}
